package org.chuan.hisports.service.Imp;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.chuan.hisports.dao.SporttypeDao;
import org.chuan.hisports.entity.Sporttype;
import org.chuan.hisports.entity.TotalTime;
import org.chuan.hisports.service.SportTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Service
public class SportTypeServiceImp implements SportTypeService {
    @Autowired
    SporttypeDao sporttypeDao;

    //查询该用户的所有运动，并根据分页插件实现分页
    @Override
    public PageInfo<Sporttype> selectAll(Integer pageNum, Integer pageSize, String uid){
        PageHelper.startPage(pageNum,pageSize);
        List<Sporttype> list = sporttypeDao.selectAll(uid);
        PageInfo<Sporttype> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    //根据日期查询该用户的所有运动，并根据分页插件实现分页
    @Override
    public PageInfo<Sporttype> selectByDate(Integer pageNum,Integer pageSize,String uid,String day){
        PageHelper.startPage(pageNum,pageSize);
        List<Sporttype> list = sporttypeDao.selectByDate(uid, day);
        PageInfo<Sporttype> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    //根据运动类型查询该用户的所有运动，并根据分页插件实现分页
    @Override
    public PageInfo<Sporttype> selectByType(Integer pageNum, Integer pageSize, String uid, String type){
        PageHelper.startPage(pageNum,pageSize);
        List<Sporttype> list = sporttypeDao.selectByType(uid, type);
        PageInfo<Sporttype> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    //根据当前日期查询最近一周的所有运动的数量
    @Override
    public List<TotalTime> selectWeek(String uid){
        List<TotalTime> list = sporttypeDao.selectWeek(uid);
        return  list;
    }
    //根据当前日期查询最近一月的所有运动的数量
    @Override
    public List<TotalTime> selectMonth(String uid){
        List<TotalTime> list = sporttypeDao.selectMonth(uid);
        return  list;
    }
    //根据当前日期查询最近一年的所有运动的数量
    @Override
    public List<TotalTime> selecYear(String uid){
        List<TotalTime> list = sporttypeDao.selectYear(uid);
        return  list;
    }

    @Override
    public void insert(Sporttype sporttype){
        sporttypeDao.insert(sporttype);
    }


}
